<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Use correct character set. -->
    <meta charset="utf-8">
    <!-- Tell IE to use the latest, best version. -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>Hello World!</title>
    <script src="./js/Cesium.js"></script>
    <style>
        @import url(./css/widgets.css);

        html, body, #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

    </style>
</head>
<body>
<div id="cesiumContainer"></div>

<script>
    var viewer = new Cesium.Viewer('cesiumContainer', {
        imageryProvider: Cesium.createOpenStreetMapImageryProvider({
            url: 'https://a.tile.openstreetmap.org/'
        }),
        showRenderLoopErrors: false,
        shouldAnimate: true
    });

    var GRAVITATIONAL_CONSTANT = 9.832;
    var entity = viewer.entities.add({
        model: {
            uri: 'model/CesiumAir/Cesium_Air.gltf',
            minimumPixelSize: 64
        },
        position: Cesium.Cartesian3.fromDegrees(-112.110693, 36.0994841, 1000.0)
    });
    viewer.trackedEntity = entity;

    // 计算当前时间点飞机模型的位置矩阵
    function computeModelMatrix(entity, time) {
        //获取位置
        var position = Cesium.Property.getValueOrUndefined(entity.position, time, new Cesium.Cartesian3());
        if (!Cesium.defined(position)) {
            return undefined;
        }
        //获取方向
        var modelMatrix;
        var orientation = Cesium.Property.getValueOrUndefined(entity.orientation, time, new Cesium.Quaternion());
        if (!Cesium.defined(orientation)) {
            modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position, undefined, new Cesium.Matrix4());
        } else {
            modelMatrix = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(orientation, new Cesium.Matrix3()), position, new Cesium.Matrix4());
        }
        return modelMatrix;
    }

    // 计算引擎(粒子发射器)位置矩阵
    function computeEmitterModelMatrix() {
        //方向
        hpr = Cesium.HeadingPitchRoll.fromDegrees(0.0, 0.0, 0.0, new Cesium.HeadingPitchRoll());
        var trs = new Cesium.TranslationRotationScale();

        //以modelMatrix(飞机)中心为原点的坐标系的xyz轴位置偏移
        trs.translation = Cesium.Cartesian3.fromElements(2.5, 3.5, 1.0, new Cesium.Cartesian3());
        trs.rotation = Cesium.Quaternion.fromHeadingPitchRoll(hpr, new Cesium.Quaternion());
        return Cesium.Matrix4.fromTranslationRotationScale(trs, new Cesium.Matrix4());
    }

    viewer.scene.primitives.add(new Cesium.ParticleSystem({
        image : 'img/fire.png',
        startScale : 1.0,
        endScale : 1.0,
        speed : 4.0,
        lifetime : 10.0,
        //主模型参数(位置)
        modelMatrix : computeModelMatrix(entity, Cesium.JulianDate.now()),
        // 发射器参数
        emitter: new Cesium.ConeEmitter(Cesium.Math.toRadians(20.0)),
        rate : 2.0,
        emitterModelMatrix : computeEmitterModelMatrix(),
        //颜色
        startColor: Cesium.Color.fromCssColorString('#FF0000'),
        endColor: Cesium.Color.fromCssColorString('#BD0000'),
        imageSize: new Cesium.Cartesian2(50, 50),
        bursts : [
            new Cesium.ParticleBurst({time : 1.0, minimum : 10, maximum : 5000}),
        ],
        emissionRate:15,
    }));

    function applyGravity(particle, dt) {
        var position = particle.position;
        var gravityVector = Cesium.Cartesian3.normalize(position, new Cesium.Cartesian3());
        Cesium.Cartesian3.multiplyByScalar(gravityVector, GRAVITATIONAL_CONSTANT * dt, gravityVector);
        particle.velocity = Cesium.Cartesian3.add(particle.velocity, gravityVector, particle.velocity);
    }



</script>


</body>
<script></script>
</html>
